function inintIcheck(){
	$('input').iCheck({
		checkboxClass: 'icheckbox_square-green',
		radioClass: 'iradio_square-green',
		increaseArea: '-10' // optional
	});
};
function getOptions(type) {
	var nowVal = parseInt($('input[type='+type+']').last().val());
	
	return nowVal+1;
};
function changeIntToEng(n) {
	switch(n)
	{
	case 1:
		return 'A、';
	case 2:
		return 'B、';
	case 3:
		return 'C、';
	case 4:
		return 'D、';
	case 5:
		return 'E、';
	case 6:
		return 'F、';
	case 7:
		return 'G、';
	case 8:
		return 'H、';
	case 9:
		return 'I、';
	case 10:
		return 'J、';
	}
};
function changeIntToEng2(n) {
	switch(n)
	{
	case 1:
		return 'A';
	case 2:
		return 'B';
	case 3:
		return 'C';
	case 4:
		return 'D';
	case 5:
		return 'E';
	case 6:
		return 'F';
	case 7:
		return 'G';
	case 8:
		return 'H';
	case 9:
		return 'I';
	case 10:
		return 'J';
	}
};
/**
 * 改变问题模版
 */
function changeQuestion(type) {
	var container = $('#question-option-container');
	var optionTemplate = _.template($("#"+type+"-init-template").html());
	
	container.html(optionTemplate);
	
	inintIcheck();
	questionEditorInit();
};

function updateQuestion(type,id){
	var container = $('#question-option-container');
	
	var optionTemplate = _.template($("#"+type+"-update-template").html());
	
	var params = {
			url: '/admin/enterprise/questions/ques-info/'+id,
			type: 'GET',
			dataType: 'json',
			data:{},
	};
	$.ajax(params).done(function(resp){
		container.html(optionTemplate({item:resp}));
		inintIcheck();
		questionEditorInit();
	});
	
	inintIcheck();
	questionEditorInit();
}

function formDataParse(type) {
	var options = new Array();
	if(type==3){
		options[0] = '论述题';
	}else{
		$("textarea[name^=option_").each(function(tk,te){
			var dataValue = $(this).attr('data-value');
			options[tk] = dataValue + "、" + '<div style="display:inline-block;">' + $(this).val() + '</div>';
		});
	}
	return options;
};

function error(erro){
	var response = eval('(' + erro.responseText + ')');
	var errors = '';
    $.each(response,function(k,v){
        errors +="<div>"+v+"</div>";
    })
    BootstrapDialog.alert({title:'提示',message:errors});
}
function questionEditorInit(){
	var editors;
	KindEditor.ready(function(K) {
		editors = K.create('.question_content', {	
			resizeType : 1,
			//allowPreviewEmoticons : false,
			afterBlur: function () { this.sync(); },
			allowImageUpload : true,
			width : "100%", 
			allowUpload : true,
			minHeight:70,
			uploadJson : '/upload/images?dest_dir=questions',
			items : ["justifyleft",'justifycenter','justifyright',"image"]
		});
	});
};
function initOptions(value){
	switch(value){
		case 0:
			changeQuestion('radio');break;
		case 1:
			changeQuestion('checkbox');break;
		case 2:
			changeQuestion('judge');break;
		case 3:
			changeQuestion('text');break;
		default :
			changeQuestion('radio');
	}
}
function updateOptions(value,id)
{
	switch(value){
		case 0:
			updateQuestion('radio',id);break;
		case 1:
			updateQuestion('checkbox',id);break;
		case 2:
			updateQuestion('judge',id);break;
		case 3:
			updateQuestion('text',id);break;
		default:
			updateQuestion('radio',id);
	}
}
function checkALL(){
	$('input[name=checkAll]').on('ifChecked', function(event){
		$('input:checkbox').iCheck('check');
	});
	$('input[name=checkAll]').on('ifUnchecked', function(event){
		$('input:checkbox').iCheck('uncheck');
	});
}
function isComEmpty(data){
	if(isNaN(data) || typeof(data) == 'undefined' || data =='' || data == '0' || data == 0){
		return true;
	} 
	return false;
}